package com.zipking.cloud.springbootmybatis.util.excel;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;

import java.util.List;

public class ExcelDataWriter<T> implements DataWriter<T> {
    private final ExcelWriter excelWriter;
    private final int writeSheet;

    public ExcelDataWriter(ExcelWriter excelWriter, int writeSheet) {
        this.excelWriter = excelWriter;
        this.writeSheet = writeSheet;
    }

    @Override
    public void writeData(int pageNum, List<T> data) {
        WriteSheet writeSheet = EasyExcel.writerSheet(this.writeSheet).build();
        excelWriter.write(data, writeSheet);
    }
}
